import { createRouter, createWebHistory } from 'vue-router';
import type { App } from 'vue';
import routes from '~/router/menu';

const publicPath = import.meta.env.VITE_APP_PUBLIC_PATH || '/';

const router = createRouter({
  history: createWebHistory(publicPath),
  scrollBehavior() {
    return {
      el: '#app',
      top: 0,
      behavior: 'smooth'
    };
  },
  routes
});

export default router;

export async function setupRouter(app: App<Element>) {
  // 异步加载所有菜单
  // await loadDynamicRoute(router);
  app.use(router);
}
